package com.hanlin.topic;

import com.hanlin.RabbitUtils;
import com.rabbitmq.client.*;

import java.io.IOException;

/**
 * 描述：
 *
 * @author:hl.yuan
 * @date:2021-03-13
 */
public class ConsumerRabbitMQ1 {


    public static void main(String[] args) throws IOException {
        Connection connection = RabbitUtils.getConnection();
        // 获取通道
        Channel channel = connection.createChannel();
        // 绑定交换机
        channel.exchangeDeclare("topics","topic");
        // 创建临时队列
        String queue = channel.queueDeclare().getQueue();

        channel.queueBind(queue,"topics","user.#");

        //消费消息
        channel.basicConsume(queue,true,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者1: "+new String(body));
            }
        });


    }

}
